/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.kj.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.alibaba.fastjson.JSONValidator;
import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.kj.entity.KjActivityJob;
import com.jeesite.modules.kj.service.KjActivityJobService;

/**
 * kj_activity_jobController
 * @author hzy
 * @version 2021-07-10
 */
@Controller
@RequestMapping(value = "${adminPath}/kj/kjActivityJob")
public class KjActivityJobController extends BaseController {

	@Autowired
	private KjActivityJobService kjActivityJobService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public KjActivityJob get(String id, boolean isNewRecord) {
		return kjActivityJobService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("kj:kjActivityJob:view")
	@RequestMapping(value = {"list", ""})
	public String list(KjActivityJob kjActivityJob, Model model) {
		model.addAttribute("kjActivityJob", kjActivityJob);
		return "modules/kj/kjActivityJobList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("kj:kjActivityJob:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<KjActivityJob> listData(KjActivityJob kjActivityJob, HttpServletRequest request, HttpServletResponse response) {
		kjActivityJob.setPage(new Page<>(request, response));
		Page<KjActivityJob> page = kjActivityJobService.findPage(kjActivityJob);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("kj:kjActivityJob:view")
	@RequestMapping(value = "form")
	public String form(KjActivityJob kjActivityJob, Model model) {
		model.addAttribute("kjActivityJob", kjActivityJob);
		return "modules/kj/kjActivityJobForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("kj:kjActivityJob:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated KjActivityJob kjActivityJob) {
		kjActivityJobService.save(kjActivityJob);
		return renderResult(Global.TRUE, text("保存活动岗位成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("kj:kjActivityJob:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(KjActivityJob kjActivityJob) {
		kjActivityJobService.delete(kjActivityJob);
		return renderResult(Global.TRUE, text("删除活动岗位成功！"));
	}
	
	/**
	 * 列表选择对话框
	 */
	@RequiresPermissions("kj:kjActivityJob:view")
	@RequestMapping(value = "kjActivityJobSelect")
	public String empUserSelect(KjActivityJob kjActivityJob, String selectData, Model model) {
		String selectDataJson = EncodeUtils.decodeUrl(selectData);
		if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()){
			model.addAttribute("selectData", selectDataJson);
		}
		model.addAttribute("KjActivityJob", kjActivityJob);
		return "modules/kj/kjActivityJobSelect";
	}
	
}